Use hash or case-statement [Ruby]
Posted
by user94154
on Stack Overflow
See other posts from Stack Overflow
or by user94154
Published on 2010-05-09T20:29:31Z
Indexed on
2010/05/09
20:38 UTC
Read the original article
Hit count: 299
Generally which is better to use?:
case n
when 'foo'
result = 'bar'
when 'peanut butter'
result = 'jelly'
when 'stack'
result = 'overflow'
return result
or
map = {'foo' => 'bar', 'peanut butter' => 'jelly', 'stack' => 'overflow'}
return map[n]
More specifically, when should I use case-statements and when should I simply use a hash?
© Stack Overflow or respective owner